<?php

class HttpHelper{
	
	public static function post($postUrl,$data,$header = ''){
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL,$postUrl);
		curl_setopt($ch, CURLOPT_POST, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		if(substr($postUrl,0,5) == 'https'){
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
		}
		if(is_array($header) && count($header)>0){
			curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
		}
		$response = curl_exec($ch);
		curl_close($ch);
		return $response;
	}

	public static function get($geturl){
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL,$geturl);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		if(strpos($geturl,'https') !== false){
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
		}
		$data = curl_exec($ch);
		curl_close($ch);
		return $data;
	}
	
}